<!DOCTYPE html>
<html>
<head>
	<title>measureText</title>
	<style>
		*{
			padding: 0;
			margin: 0;
		}
	</style>
</head>
<body>

	<!-- <div style="border: 1px solid red; width: 200px; height: 30px;"></div> -->

	<canvas id="canvas" width="500" height="300" style="border: 1px solid #ccc;"></canvas>

	<script type="text/javascript">
		
		var c=document.getElementById("canvas");
		var ctx=c.getContext("2d");

		ctx.font="30px Arial";
		var txt="Hello World";

		console.log(ctx.measureText(txt))

		ctx.fillText("width:" + ctx.measureText(txt).width, 10, 50)

		ctx.fillText(txt,10,20);

	</script>
</body>
</html>